class Solution {
    public:
        int maxSatisfied(vector<int>& customers, vector<int>& grumpy, int m) {
            int ans = 0;
            int maxs = 0;
            int temp = 0;
            for (int i = 0; i < customers.size(); i++) {
                if (grumpy[i] == 0) {
                    ans += customers[i];
                }
            }
            for (int i = 0; i < m; i++) { // 滑入m个元素
                if (grumpy[i] == 1) {
                    temp += customers[i];
                }
            }
            maxs = max(maxs, temp);
            for (int i = m; i < customers.size(); i++) {
                if (grumpy[i] == 1) { // 末尾滑入1个
                    temp += customers[i];
                }
                if (grumpy[i - m] == 1) { // 首部滑出1个
                    temp -= customers[i - m];
                }
                maxs = max(maxs, temp);
            }
            return ans + maxs;
        }
    };